package com.chagee.store.operation.server.service;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import com.chagee.store.operation.api.bo.Location;
import com.chagee.store.operation.api.enums.IdentifyImageLocationEnum;
import com.chagee.store.operation.api.response.BaiduAiDetectResponse;
import com.chagee.store.operation.common.constant.AiEvsParamsConstant;
import com.chagee.store.operation.common.constant.SupplierWorkOrderConstant;
import com.chagee.store.operation.common.exception.BizErrorCode;
import com.chagee.store.operation.common.exception.ParamBizException;
import com.chagee.store.operation.api.response.vo.AiResultVO;
import com.chagee.store.operation.server.utils.Base64Util;
import com.chagee.store.operation.server.utils.GenerateBaiduAiTokenUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Lee
 * @description 百度AI识别服务
 * @date 2024/8/13 10:27
 */
@Service
@Slf4j
public class BaiduAiIdentifyService {

	@Value("${evs-ai.accessKey}")
	private String aiAccessKey;

	@Value("${evs-ai.secretKey}")
	private String aiSecretKey;

	@Value("${evs-ai.host}")
	private String aiHost;

	@Value("${evs-ai.tokenUri}")
	private String aiTokenUri;

	@Value("${evs-ai.peristalticPumpUri}")
	private String peristalticPumpUri;

	@Value("${evs-ai.airOutletUri}")
	private String airOutletUri;

	@Value("${evs-ai.iceBlancMilkBoxUri}")
	private String iceBlancMilkBoxUri;

	@Value("${evs-ai.outletClingFilmUri}")
	private String outletClingFilmUri;

	/**
	 * 百度AI识别图片
	 * 出茶口TEA_OUTLET/料仓SILO/出风口OUTLET/蠕动泵PERISTALTIC_PUMP/门框滑轨DOOR_FRAME_SLIDING_RAIL/茶饮机表面TEA_DRINKING_MACHINE_SURFACE
	 *
	 * @param type      类型
	 * @param imagePath 图片连接
	 */
	public HttpResponse dealWorkOrderAI(String type, String imagePath) {
		// header: x-evs-user, 填写userId，可以从百度智能云控制台上算子仓库-ai鉴权查看（ak）
		String ak = aiAccessKey;
		// 填写sk，可以从百度智能云控制台上算子仓库-ai鉴权查看
		String sk = aiSecretKey;
		//host
		String host = aiHost;
		String tokenUri = aiTokenUri;

		//request uri
		String uri = "";
		//出茶口（出料口清洁检测）
		if (IdentifyImageLocationEnum.TEA_OUTLET.getType().equals(type)) {
			uri = outletClingFilmUri;
		}
		//料仓（牛奶冰勃朗料盒清洁检测）
		if (IdentifyImageLocationEnum.SILO.getType().equals(type)) {
			uri = iceBlancMilkBoxUri;
		}
		//出风口（出风口清洁检测）
		if (IdentifyImageLocationEnum.OUTLET.getType().equals(type)) {
			uri = airOutletUri;
		}
		//蠕动泵（蠕动泵清洁检测）
		if (IdentifyImageLocationEnum.PERISTALTIC_PUMP.getType().equals(type)) {
			uri = peristalticPumpUri;
		}
		//TODO 门框滑轨/茶饮机表面 待添加

		//入参
		JSONObject jsonObject = new JSONObject();

		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_URL_KEY, imagePath);
		// 将JSONObject转换为JSON字符串
		String jsonString = jsonObject.toString();
		// 压缩JSON字符串（去除空格、换行符等）
		String compressedJsonString = jsonString.replaceAll("\\s", "");
		// 计算压缩后的字符串的MD5值
		String md5 = DigestUtils.md5Hex(compressedJsonString);
		Map<String, String> paramsWithNodeAuth = GenerateBaiduAiTokenUtil.getParamsWithNodeAuth(tokenUri, md5, ak, sk);
		log.info("BaiduAiIdentifyService.dealWorkOrderAI request:{}", compressedJsonString);
		HttpResponse execute = HttpRequest.post(host.concat(tokenUri).concat(uri))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_TYPE, AiEvsParamsConstant.AUTH_PARA_KEY_VALUE)
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_USER, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_USER))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH))
			.body(compressedJsonString)
			.execute();
		log.info("BaiduAiIdentifyService.dealWorkOrderAI response:{}", execute.body());
		return execute;
	}

	/**
	 * 处理data数据
	 */
	public AiResultVO parseResultResponse(String body) {
		AiResultVO aiResultVO = new AiResultVO();
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			JsonNode rootNode = objectMapper.readTree(body);
			JsonNode code = rootNode.path("code");
			if (!code.isMissingNode() || !code.isNull()) {
				aiResultVO.setCode(code.asLong());
			}
			JsonNode message = rootNode.path("message");
			if (!message.isMissingNode() || !message.isNull()) {
				aiResultVO.setMessage(message.asText());
			}
			JsonNode data = rootNode.path("data");
			if (!data.isMissingNode() || !data.isNull()) {
				aiResultVO.setItemCount(rootNode.path("item_count").asLong());
				List<BaiduAiDetectResponse> baiduAiDetectResponses = new ArrayList<>();
				JsonNode itemsNode = rootNode.path("data").path("items");
				for (JsonNode itemNode : itemsNode) {
					BaiduAiDetectResponse baiduAiDetectResponse = new BaiduAiDetectResponse();
					int id = itemNode.path("id").asInt();
					String label = itemNode.path("label").asText();
					JsonNode location = itemNode.path("location");
					double height = location.path("height").asDouble();
					double left = location.path("left").asDouble();
					double top = location.path("top").asDouble();
					double width = location.path("width").asDouble();
					double score = itemNode.path("score").asDouble();
					// 解析结果
					baiduAiDetectResponse.setId(id);
					baiduAiDetectResponse.setLabel(label);
					baiduAiDetectResponse.setScore(Math.round(score * 100));
					baiduAiDetectResponse.setLocation(
						Location.builder()
							.width(width)
							.height(height)
							.left(left)
							.top(top)
							.build());
					baiduAiDetectResponses.add(baiduAiDetectResponse);
				}
				aiResultVO.setItems(baiduAiDetectResponses);
			}
		} catch (Exception e) {
			log.error("BaiduAiIdentifyService.parseResponse.error:{}", e.getMessage());
		}
		return aiResultVO;
	}



	/**
	 * 蠕动泵清洁检测
	 *
	 * @param imagePath 图片地址
	 * @return 检测结果
	 */
	public List<BaiduAiDetectResponse> identifyPeristalticPump(String imagePath) {
		// header: x-evs-user, 填写userId，可以从百度智能云控制台上算子仓库-ai鉴权查看（ak）
		String ak = aiAccessKey;
		// 填写sk，可以从百度智能云控制台上算子仓库-ai鉴权查看
		String sk = aiSecretKey;
		//host
		String host = aiHost;
		String tokenUri = aiTokenUri;
		//request uri
		String uri = peristalticPumpUri;

		//入参
		JSONObject jsonObject = new JSONObject();

//		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_64_KEY, imageBase64);
		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_URL_KEY, imagePath);
		// 将JSONObject转换为JSON字符串
		String jsonString = jsonObject.toString();
		// 压缩JSON字符串（去除空格、换行符等）
		String compressedJsonString = jsonString.replaceAll("\\s", "");
		// 计算压缩后的字符串的MD5值
		String md5 = DigestUtils.md5Hex(compressedJsonString);
		Map<String, String> paramsWithNodeAuth = GenerateBaiduAiTokenUtil.getParamsWithNodeAuth(tokenUri, md5, ak, sk);
		log.info("BaiduAiIdentifyService.identifyPeristalticPump request:{}", compressedJsonString);
		String body = HttpRequest.post(host.concat(tokenUri).concat(uri))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_TYPE, AiEvsParamsConstant.AUTH_PARA_KEY_VALUE)
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_USER, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_USER))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH))
			.body(compressedJsonString)
			.execute().body();
		log.info("BaiduAiIdentifyService.identifyPeristalticPump response:{}", body);
		return parseResponse(body);
	}

	/**
	 * 出风口清洁检测
	 *
	 * @param imagePath 图片地址
	 * @return 检测结果
	 */
	public List<BaiduAiDetectResponse> identifyAirOutlet(String imagePath) {
		// header: x-evs-user, 填写userId，可以从百度智能云控制台上算子仓库-ai鉴权查看（ak）
		String ak = aiAccessKey;
		// 填写sk，可以从百度智能云控制台上算子仓库-ai鉴权查看
		String sk = aiSecretKey;
		//host
		String host = aiHost;
		String tokenUri = aiTokenUri;
		//request uri
		String uri = airOutletUri;

		//入参
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_URL_KEY, imagePath);
		// 将JSONObject转换为JSON字符串
		String jsonString = jsonObject.toString();
		// 压缩JSON字符串（去除空格、换行符等）
		String compressedJsonString = jsonString.replaceAll("\\s", "");
		// 计算压缩后的字符串的MD5值
		String md5 = DigestUtils.md5Hex(compressedJsonString);
		Map<String, String> paramsWithNodeAuth = GenerateBaiduAiTokenUtil.getParamsWithNodeAuth(tokenUri, md5, ak, sk);
		log.info("BaiduAiIdentifyService.identifyAirOutlet request:{}", compressedJsonString);
		String body = HttpRequest.post(host.concat(tokenUri).concat(uri))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_TYPE, AiEvsParamsConstant.AUTH_PARA_KEY_VALUE)
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_USER, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_USER))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH))
			.body(compressedJsonString)
			.execute().body();
		log.info("BaiduAiIdentifyService.identifyAirOutlet response:{}", body);
		return parseResponse(body);
	}

	/**
	 * 牛奶冰勃朗料盒清洁检测
	 *
	 * @param imagePath 图片地址
	 * @return 检测结果
	 */
	public List<BaiduAiDetectResponse> identifyIceBlancMilkBox(String imagePath) {
		// header: x-evs-user, 填写userId，可以从百度智能云控制台上算子仓库-ai鉴权查看（ak）
		String ak = aiAccessKey;
		// 填写sk，可以从百度智能云控制台上算子仓库-ai鉴权查看
		String sk = aiSecretKey;
		//host
		String host = aiHost;
		String tokenUri = aiTokenUri;
		//request uri
		String uri = iceBlancMilkBoxUri;

		//入参
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_URL_KEY, imagePath);
		// 将JSONObject转换为JSON字符串
		String jsonString = jsonObject.toString();
		// 压缩JSON字符串（去除空格、换行符等）
		String compressedJsonString = jsonString.replaceAll("\\s", "");
		// 计算压缩后的字符串的MD5值
		String md5 = DigestUtils.md5Hex(compressedJsonString);
		Map<String, String> paramsWithNodeAuth = GenerateBaiduAiTokenUtil.getParamsWithNodeAuth(tokenUri, md5, ak, sk);
		log.info("BaiduAiIdentifyService.identifyIceBlancMilkBox request:{}", compressedJsonString);
		String body = HttpRequest.post(host.concat(tokenUri).concat(uri))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_TYPE, AiEvsParamsConstant.AUTH_PARA_KEY_VALUE)
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_USER, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_USER))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH))
			.body(compressedJsonString)
			.execute().body();
		log.info("BaiduAiIdentifyService.identifyIceBlancMilkBox response:{}", body);
		return parseResponse(body);
	}

	/**
	 * 出料口清洁检测
	 *
	 * @param imagePath 图片地址
	 * @return 检测结果
	 */
	public List<BaiduAiDetectResponse> identifyOutletClingFilm(String imagePath) {
		// header: x-evs-user, 填写userId，可以从百度智能云控制台上算子仓库-ai鉴权查看（ak）
		String ak = aiAccessKey;
		// 填写sk，可以从百度智能云控制台上算子仓库-ai鉴权查看
		String sk = aiSecretKey;
		//host
		String host = aiHost;
		String tokenUri = aiTokenUri;
		//request uri
		String uri = outletClingFilmUri;

		//入参
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(AiEvsParamsConstant.BAI_DU_AI_PARAM_URL_KEY, imagePath);
		// 将JSONObject转换为JSON字符串
		String jsonString = jsonObject.toString();
		// 压缩JSON字符串（去除空格、换行符等）
		String compressedJsonString = jsonString.replaceAll("\\s", "");
		// 计算压缩后的字符串的MD5值
		String md5 = DigestUtils.md5Hex(compressedJsonString);
		Map<String, String> paramsWithNodeAuth = GenerateBaiduAiTokenUtil.getParamsWithNodeAuth(tokenUri, md5, ak, sk);
		log.info("BaiduAiIdentifyService.identifyOutletClingFilm request:{}", compressedJsonString);
		String body = HttpRequest.post(host.concat(tokenUri).concat(uri))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_TYPE, AiEvsParamsConstant.AUTH_PARA_KEY_VALUE)
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_USER, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_USER))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_DATE))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_MD5))
			.header(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH, paramsWithNodeAuth.get(AiEvsParamsConstant.AUTH_PARAM_KEY_AUTH))
			.body(compressedJsonString)
			.execute().body();
		log.info("BaiduAiIdentifyService.identifyOutletClingFilm response:{}", body);
		return parseResponse(body);
	}

	/**
	 * 解析百度AI接口响应
	 *
	 * @param jsonResponse 响应报文
	 * @return 自定义响应报文
	 */
	private List<BaiduAiDetectResponse> parseResponse(String jsonResponse) {
//		jsonResponse = "{ \"code\": 20020, \"message\": \"\", \"data\": { \"item_count\": 1, \"items\": [ { \"id\": 1, \"label\": \"outlet_cling_film\", \"location\": { \"height\": 14, \"left\": 821.5, \"top\": 254, \"width\": 36 }, \"score\": 0.7842945456504822 } ] } } }";
//		jsonResponse = "{    \"code\": 200,    \"data\": {},    \"message\": \"\"}";
		List<BaiduAiDetectResponse> responseList = new ArrayList<>();
		int code = 0;
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			JsonNode rootNode = objectMapper.readTree(jsonResponse);

			code = rootNode.path("code").asInt();
			String message = rootNode.path("message").asText();
			JsonNode data = rootNode.path("data");
			if (data != null) {
				JsonNode itemsNode = rootNode.path("data").path("items");
				for (JsonNode itemNode : itemsNode) {
					BaiduAiDetectResponse baiduAiDetectResponse = new BaiduAiDetectResponse();
					int id = itemNode.path("id").asInt();
					String label = itemNode.path("label").asText();
					JsonNode location = itemNode.path("location");
					double height = location.path("height").asDouble();
					double left = location.path("left").asDouble();
					double top = location.path("top").asDouble();
					double width = location.path("width").asDouble();
					double score = itemNode.path("score").asDouble();

					// 解析结果
					baiduAiDetectResponse.setId(id);
					baiduAiDetectResponse.setLabel(label);
					baiduAiDetectResponse.setScore(Math.round(score * 100));
					baiduAiDetectResponse.setLocation(
						Location.builder()
							.width(width)
							.height(height)
							.left(left)
							.top(top)
							.build());
					responseList.add(baiduAiDetectResponse);
				}
			}

		} catch (Exception e) {
			log.error("BaiduAiIdentifyService.parseResponse.error:{}", e.getMessage());
		}
		throwParamException(code, responseList);
		return responseList;
	}

	/**
	 * 异常转换
	 *
	 * @param code         异常码
	 * @param responseList 异常相应参数
	 */
	private void throwParamException(Integer code, List<BaiduAiDetectResponse> responseList) {
		// common异常
		if (SupplierWorkOrderConstant.AI_COMMON_EXP_PARAM_ERROR.equals(code)
			|| SupplierWorkOrderConstant.AI_COMMON_EXP_PARAM_IS_NULL.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_PARAM_ERROR, responseList);
		}
		if (SupplierWorkOrderConstant.AI_COMMON_EXP_NOT_FOUND.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_NOT_FOUND, responseList);
		}
		if (SupplierWorkOrderConstant.AI_COMMON_EXP_INTERNAL_ERROR.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_INTERNAL_ERROR, responseList);
		}
		if (SupplierWorkOrderConstant.AI_COMMON_EXP_IMAGE_INVALID.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_IMAGE_INVALID, responseList);
		}

		// 蠕动泵异常
		if (SupplierWorkOrderConstant.PERISTALTIC_PUMP_SUCCESS_NO_CODE_1.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_PERISTALTIC_PUMP_FAIL_1, responseList);
		}
		if (SupplierWorkOrderConstant.PERISTALTIC_PUMP_SUCCESS_NO_CODE_2.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_PERISTALTIC_PUMP_FAIL_2, responseList);
		}
		if (SupplierWorkOrderConstant.PERISTALTIC_PUMP_SUCCESS_NO_CODE_3.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_PERISTALTIC_PUMP_FAIL_3, responseList);
		}

		// 出风口异常
		if (SupplierWorkOrderConstant.AIR_OUTLET_SUCCESS_NO_CODE_1.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_AIR_OUTLET_FAIL_1, responseList);
		}
		if (SupplierWorkOrderConstant.AIR_OUTLET_SUCCESS_NO_CODE_2.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_AIR_OUTLET_FAIL_2, responseList);
		}
		if (SupplierWorkOrderConstant.AIR_OUTLET_SUCCESS_NO_CODE_3.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_AIR_OUTLET_FAIL_3, responseList);
		}

		// 牛奶冰勃朗料盒异常
		if (SupplierWorkOrderConstant.ICE_BLANC_MILK_BOX_SUCCESS_NO_CODE_1.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_ICE_BLANC_MILK_BOX_FAIL_1, responseList);
		}
		if (SupplierWorkOrderConstant.ICE_BLANC_MILK_BOX_SUCCESS_NO_CODE_2.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_ICE_BLANC_MILK_BOX_FAIL_2, responseList);
		}

		// 出料口清洁异常
		if (SupplierWorkOrderConstant.OUTLET_CLING_FILM_SUCCESS_NO_CODE_1.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_OUTLET_CLING_FILM_FAIL_1, responseList);
		}
		if (SupplierWorkOrderConstant.OUTLET_CLING_FILM_SUCCESS_NO_CODE_2.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_OUTLET_CLING_FILM_FAIL_2, responseList);
		}
		if (SupplierWorkOrderConstant.OUTLET_CLING_FILM_SUCCESS_NO_CODE_3.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_OUTLET_CLING_FILM_FAIL_3, responseList);
		}
		if (SupplierWorkOrderConstant.OUTLET_CLING_FILM_SUCCESS_NO_CODE_4.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_OUTLET_CLING_FILM_FAIL_4, responseList);
		}
		if (SupplierWorkOrderConstant.OUTLET_CLING_FILM_SUCCESS_NO_CODE_5.equals(code)) {
			throw new ParamBizException(BizErrorCode.IDENTIFY_OUTLET_CLING_FILM_FAIL_5, responseList);
		}
	}

	/**
	 * 图像转base64
	 *
	 * @param imageFile 图片
	 * @return base64编码
	 */
	private static String encodeImageToBase64(File imageFile) {
		// 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
		// 其进行Base64编码处理
		byte[] data = null;
		// 读取图片字节数组
		try {
			InputStream in = Files.newInputStream(imageFile.toPath());
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 对字节数组Base64编码
		Base64Util encoder = new Base64Util();
		return encoder.encode(data);
	}
}
